home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
ubas830.zip
/
MALM.EXE
/
TSTCHN.UB
< prev
next >
Wrap
Text File
|
1990-08-22
|
2KB
|
48 lines
10 ' Test program for Chinese
15 dim A(20),B(20),M(20)
20 print "How many congruences: "
30 input N%
40 print "Enter the congruences A, B, M"
50 for I=1 to N%
60 input A(I),B(I),M(I)
70 next I
80 print "**********************"
90 print N%,"Congruences"
100 print:print "A","B","M"
110 for I=1 to N%
120 print A(I),B(I),M(I)
130 next I:print:print
140 gosub *Chinese(N%,&A(),&B(),&M(),&Soln,&Modulus)
150 print "modulus is: ",Modulus
160 if Modulus<>0 then print "Solution: ";Soln
170 end
1170 *Chinese(N%,&A(),&B(),&M(),&Soln,&Modulus)
1180 ' Chinese remaindering algorithm, modeled on the Pascal version.
1190 ' 21 August 1990
1200 local C,Ca,Te,Ta,I%,Aa,Bb
1210 if N%<=0 then Modulus=0:return endif
1220 gosub *Fcgcd(A(1),M(1),&C,&Ca)
1230 Te=B(1)\C:if res then Modulus=0:return endif
1240 Soln=Te*Ca:Modulus=M(1)\C
1250 for I%=2 to N%
1260 Aa=A(I%)*Modulus:Bb=B(I%)-A(I%)*Soln
1270 gosub *Fcgcd(Aa,M(I%),&C,&Ca)
1280 Te=Bb\C:if res then Modulus=0:cancel for:return endif
1290 Soln=Soln+Modulus*Te*Ca
1300 Modulus=Modulus*(M(I%)\C)
1310 Soln=Soln@Modulus
1320 next I%
1330 return ' End of subroutine Chinese
2330 *Fcgcd(A,B,&C,&Ca)
2340 ' Gcd with one coefficient. c is the gcd of a and b.
2350 ' ca*a + cb*b = c for some cb 16 April 1990
2360 local R,Q,T,Af,Bf,B1
2370 Ca=1:B1=0:Af=A:Bf=B
2380 while B
2390 T=B:Q=A\B:B=res
2400 R=Ca-Q*B1:Ca=B1:B1=R:A=T
2410 wend
2420 C=A
2430 if C<0 then neg C:neg Ca endif
2440 return:' End of procedure Fcgcd.